/*
* 封装 MYSQL CRUD 操作
* 读取抓斗数据
*/

const db = require('../lib/mysql/db.js');

// 通过时间范围获取
exports.getDataByRange = async (start_time, end_time) => {
    const start_timestamp = Math.floor(((new Date(start_time)).getTime())/1000);
    const end_timestamp = Math.floor(((new Date(end_time)).getTime())/1000);
    const sql = 'SELECT SUM(hev) as value FROM log WHERE time >= ? and time <= ?';
    const rows = await db.query(sql, [start_timestamp, end_timestamp]);
    return rows ? rows[0] : 0;
};
